﻿using AgencyManagerSystem.Model;
using System.Collections.Generic;
using Dapper;

namespace AgencyManagerSystem.DataFetcher
{
    public class RoleTableFetcher : DetailFetcher<RoleTableModel>
    {
        public override IList<RoleTableModel> ListDetail(int mainId)
        {
            Condition[] conditions = new Condition[] { new Condition() { Key = "Role", Op = "=", Value = mainId } };
            var list = List(conditions);
            return list;
        }

        public override IList<RoleTableModel> ListDetail(int mainId, int pos, int size)
        {
            Condition[] conditions = new Condition[] { new Condition() { Key = "Role", Op = "=", Value = mainId } };
            var list = List(conditions, pos, size);
            return list;
        }

        public IList<RoleTableModel> ListByUser(int uid, int domain)
        {
            string sqlstr = "SELECT * FROM SYS_ROLETABLE WHERE ROLE IN (SELECT ROLE FROM SYS_ROLEUSER WHERE USER = @USER AND DOMAIN = @DOMAIN)";
            DynamicParameters dynamicParameters = new DynamicParameters();
            dynamicParameters.Add("@USER",uid);
            dynamicParameters.Add("@DOMAIN", domain);
            var result = DBHelper.GetTran().Query<RoleTableModel>(sqlstr, dynamicParameters).AsList();
            return result;
        }
    }
}
